package com.zyg.manager.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zyg.common.utils.PageUtils;
import com.zyg.common.utils.Query;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.Map;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.zyg.manager.dao.BrandDao;
import com.zyg.manager.entity.BrandEntity;
import com.zyg.manager.service.BrandService;


@Service("brandService")
public class BrandServiceImpl extends ServiceImpl<BrandDao, BrandEntity> implements BrandService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String key = (String) params.get("key");
        QueryWrapper<BrandEntity> queryWrapper = new QueryWrapper<>();
        //1. 封装查询条件
        if(StringUtils.isNotBlank(key)){
            queryWrapper.like("name",key);
            queryWrapper.or().eq("first_char",key);
            queryWrapper.or().like("id",key);

        }
        //2. 开始分页查询
        IPage<BrandEntity> page = this.page(
                new Query<BrandEntity>().getPage(params),
                queryWrapper
        );

        return new PageUtils(page);
    }

}